{% from "shuup/admin/macros/block.jinja" import link_block %}

{% set categories = shuup_admin.get_menu_entry_categories() %}
{% set quicklinks = shuup_admin.get_quicklinks() %}

<nav id="js-main-menu" class="main-menu">
    <div class="scroll-inner-content">
        <div class="logo-wrap d-flex align-items-center justify-content-between">
            <a class="logo" href="{{ url('shuup_admin:dashboard') }}" data-toggle="tooltip" data-placement="bottom" title="{% trans %}Dashboard{% endtrans %}">Shuup</a>
            <div class="d-block d-lg-none">
                <a id="js-menu-close" class="mobile-menu-close d-inline-block" href="#">
                    <i class="fa fa-times"></i>
                </a>
            </div>
        </div>
        <ul class="menu-list">
            {% if quicklinks %}
                <li class="quicklinks">
                    <a class="item-category d-flex align-items-center mt-3 mb-3" href="#">
                        <i class="item-icon fa fa-bolt"></i>
                        <span class="item-name parent">{% trans %}Quicklinks{% endtrans %}</span>
                        <i class="ml-auto item-arrow fa fa-chevron-down"></i>
                    </a>
                    <ul class="submenu quicklinks-submenu">
                        {% for category, links in quicklinks.items() %}
                            <li><h5 class="pt-4 pb-1">{{ category.label }}</h5></li>
                            {% for quicklink in links %}
                                {% for action in quicklink.actions %}
                                    <li>
                                        <a class="pl-0 pr-0 pt-2 pb-2" href="{{ action.url }}{% if redirect %}?redirect={{ redirect }}{% endif %}">
                                            {% if quicklink.icon_url %}
                                                <img class="mr-3" src="{{ static(quicklink.icon_url) }}">
                                            {% endif %}
                                            <span>{{ action.text }}</span>
                                        </a>
                                    </li>
                                {% endfor %}
                            {% endfor %}
                        {% endfor %}
                    </ul>
                </li>
            {% endif %}
            {% for category in categories %}
                {% if not category.is_hidden %}
                    {% set only_entry = (category.entries|first if (category.entries|length == 1 and not category.url and category.entries[0].name == category.name) else None) %}
                    {% set has_children = not only_entry and category.has_entries %}
                    {% set breadcrumbs = (breadcrumbs or shuup_admin.get_breadcrumbs()) %}
                    {% set is_menu_category_active = shuup_admin.is_menu_category_active(category, request.path, breadcrumbs) %}
                    <li>
                        <a
                                class="{% if has_children %}item-category {% endif %}d-flex align-items-center mt-3 mb-3{% if is_menu_category_active %} item-active{% endif %}"
                                href="{% if only_entry %}{{ only_entry.url }}{% else %}{{ category.url if category.url != None else '#' }}{% endif %}"
                                data-target-id="category-{{ category.identifier }}"
                        >
                            <i class="item-icon {{ category.icon }}"></i>
                            <span class="item-name parent">{{ category.name }}</span>
                            {% if has_children %}
                                <i class="ml-auto item-arrow fa fa-chevron-down {% if is_menu_category_active %}rotate{% endif %}"></i>
                            {% endif %}
                        </a>
                        <ul class="submenu{% if is_menu_category_active %} active{% endif %}">
                            {% if not only_entry %}
                                {% for entry in category %}
                                    {% if not entry.is_hidden %}
                                        {% set is_active = shuup_admin.is_menu_item_active(entry.url, request.path, breadcrumbs) %}
                                        <li><a class="item-submenu {{ 'active-menu' if is_active else '' }}" href="{{ entry.url }}">{{ entry.text }}</a></li>
                                    {% endif %}
                                {% endfor %}
                            {% endif %}
                        </ul>
                    </li>
                {% endif %}
            {% endfor %}
        </ul>
    </div>
</nav>

